import java.util.Scanner;

/**
 * Created by forcht on 2018/4/26.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scanner.nextInt();
        }
        int max=0;
        int i=0;
        int j=1;
        int sum=0;
        boolean flag;
        boolean c;
        while (i<n){
            max=0;
            j=i+1;
            if (j>=n)j=0;
            if(i<j)flag=a[i]>=a[j];
            else flag=a[i]>a[j];
            c=false;
           while (flag){
               if(a[j]>=max){
                   sum++;
                   max=a[j];
               }
               j++;
               if(j>=n)j=0;
               if (i==j){
                   c=true;
                   break;
               }
               else if(i<j)flag=a[i]>=a[j];
               else flag=a[i]>a[j];
           }
           max=0;
           j=i-1;
           if (j<0)j=n-1;
           while (!c&&a[i]>a[j]){
               if(a[j]>=max){
                   sum++;
                   max=a[j];
               }
               j--;
               if(j<0)j=n-1;
               if(i==j)break;
           }
           i++;
        }
        System.out.println(sum);
    }
}
